﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRM.BIZ;
using HRM.Entity;
using HRM.Utility;
using WebUI.UserControls;

namespace WebUI.Pages
{
    public partial class ContractTypeManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        protected void LoadData()
        {
            ContractTypeBiz contractBiz = new ContractTypeBiz();
            ucContractTypeManagement.DataSource = contractBiz.GetAll();
            ucContractTypeManagement.LoadItemList();
        }

        protected void ucContractTypeManagement_AddItem(object sender, ItemManagementEventArgs e)
        {
            ContractTypeBiz contractBiz = new ContractTypeBiz();
            ContractType contract = new ContractType();
            contract.Name = e.Name;
            contractBiz.Add(contract);
            (Master as DefaultMasterPage).RunStartupScript("displayMessage('Thêm thành công')");
            ucContractTypeManagement.SetActionPanelVisible(false);
            LoadData();
        }

        protected void ucContractTypeManagement_SaveEditItem(object sender, ItemManagementEventArgs e)
        {
            ContractTypeBiz contractBiz = new ContractTypeBiz();
            ContractType contract = contractBiz.GetByID(e.ID);
            if (contract != null)
            {
                contract.Name = e.Name;
                contractBiz.Update(contract);
                (Master as DefaultMasterPage).RunStartupScript("displayMessage('Cập nhật thành công')");
                ucContractTypeManagement.SetActionPanelVisible(false);
                LoadData();
            }
        }

        protected void ucContractTypeManagement_DeleteItem(object sender, ItemManagementEventArgs e)
        {
            ContractTypeBiz contractBiz = new ContractTypeBiz();
            contractBiz.Delete(e.ID);
            LoadData();
        }
    }
}
